/***************************************************************************
 * The Open Armory API is a project to retrieve World of Warcraft(R) 
 * related XML data from The Armory.
 * 
 * The data retrieved via the Open Armory API from The Armory is 
 * proprietary to Blizzard Entertainment, Inc(R).
 * *************************************************************************
 * Copyright (C) 2009 - 2010 Tedla M.B. Brandsema
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
package net.openarmory.core.domain.constants;

import java.io.IOException;

import net.openarmory.core.config.ConfigurationProperties;
import net.openarmory.core.domain.url.UrlConnectionReader;

import org.apache.log4j.Logger;

// TODO: Auto-generated Javadoc
/**
 * The Enum ArmoryZone.
 */
public enum ArmoryZone implements ArmoryEnum {

	/** The EU. */
	EU,

	/** The US. */
	US;

	/** The log. */
	private static final Logger LOG = Logger
			.getLogger(UrlConnectionReader.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.openarmory.domain.constants.ConsoleEnum#getConsoleParameterValue()
	 */
	@Override
	public String getConsoleParameterValue() {
		return this.toString();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.openarmory.domain.constants.ArmoryEnum#getUrlConfigProperty()
	 */
	@Override
	public String getUrlConfigProperty() {
		ConfigurationProperties config = null;
		try {
			config = ConfigurationProperties.getInstance();
		} catch (final IOException e) {
			LOG.error("Unable to open configuration.properties file.", e);
		}

		switch (this) {
		case EU:
			return config.getArmoryUrlEu();
		case US:
			return config.getArmoryUrlUs();
		default:
			// TODO: throw custom zone exception
			return null;
		}
	}

	/**
	 * Gets the string values.
	 * 
	 * @return the string values
	 */
	public static String getStringValues() {
		final StringBuilder concat = new StringBuilder();
		for (final ArmoryZone armoryZone : ArmoryZone.values()) {
			concat.append(armoryZone.getConsoleParameterValue() + ", ");
		}
		return concat.toString().replaceAll(", $", "");
	}

}
